<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<!DOCTYPE html>
<html lang="en">
  <head>
     <%@include file="/WEB-INF/jsp/common/style.jsp"%>
     <c:set var="ctx" value="${pageContext.request.contextPath}"/>
	<script type="text/javascript">
		var basePath = "${ctx}";
	</script>
    <link href="${ctx}/css/jquery.treeview.css" rel="stylesheet">
    
    <link rel="Favicon Icon" href="favicon.ico">
   <script type="text/javascript" src="${ctx}/js/jquery.min.js"></script>
    <script src="${ctx}/js/jquery.treeview.js" type="text/javascript"> </script>
  </head>
  <body>
    <div id="wrap">
    
	<form class="form-horizontal"  id="seachform" action="${pageContext.request.contextPath}/set/product/index"	method="post">
	<input  type="hidden" name="catId" id="cateId" />
	<input type="hidden" name="catLevel" id="catLevel" value="${model.catLevel}" />
    <div   class="container-fluid">
     
      <!-- Main window -->
      <div class="main_container" id="dashboard_page">

		 <div class="row-fluid">
          <div class="widget widget-padding span12">
              <h4 class="widget-head-title">产品管理</h4>
									<div class="widget-header">
										<span>首页&nbsp;>&nbsp;产品管理</span>
			</div>
		  <div class="row-fluid" style="background-color:#fff;padding:20px 20px;">
		  	  <div style="float:left">
	  	  			<span style="width:70px">项目名称:</span>
	  	  			<input name="projectName" value="${model.projectName}"  type="text" class=""/>
	  	  		</div>
	  	  		<div style="float:left;margin-left:30px">
	  	  			<span style="width:70px">产品名称:</span>
	  	  			<input name="itemName" value="${model.itemName}" type="text" class="" />
	  	  		</div>
	  	  		<div id="treediv1" style="float:left;margin-left:30px">
	  	  			<span style="width:70px">品类:</span>
	  	  			<input name="catName" id="catName" onclick="showCategory()" autocomplete="off" id="catName" value="${model.catName}" type="text" class="" />
	  	  			<div id="treediv"  class="treecategory" style="margin-left:37px">
				  		
			    	</div>
	  	  		</div>
        </div>
        <div class="row-fluid" style="background-color:#fff;padding:20px 20px;">
        	<div style="float:left">
		  	  			<span style="width:70px">创建时间:</span>
		  	  			<input  readOnly=true class="Wdate" type="text" name="startTime" id="d17" value="${model.startTime}" onFocus="WdatePicker({dateFmt:'yyyy/MM/dd'})"/>
		  	  		</div>
		  	  		<div style="float:left;margin-left:30px">
		  	  			<span style="width:70px">至</span>
		  	  			<input style="margin-left:45px" readOnly=true class="Wdate" type="text" name="endTime" id="d18"  value="${model.endTime}" onFocus="WdatePicker({dateFmt:'yyyy/MM/dd'})"/>
		  	  		</div>
        </div>
       </div>
      </div>
      
       <div class="row-fluid">
      	 <div >
               <input class="btn btn-primary" type="submit" value="查询"/>            
               <input class="btn btn-success buttonrole" type="button"  name="btnadd" onclick="edit('')" value="新增"/>
               <input class="btn btn-warning buttonrole" type="button"  name="btnexport" onclick="exportXls('')" value="导出excel"/>
               
            </div>
		</div>
		<div class="row-fluid">
          <div class="widget widget-padding span12">
            <div class="widget-header">
              <i class="icon-group"></i>
              <h5>查询结果</h5>
            
            </div>  
            <div class="widget-body">
              <div class="table-scroll">
				  <table id="users" class="table table-striped table-bordered dataTable">
					  <thead>
					  <tr>
						  <th>项目名称</th>
						  <th>产品名称</th>
						  <th>产品建议售价</th>
						  <th>核心产品</th>
						  <th>自有渠道产品</th>
						  <th>产品经理</th>
						  <th>品类</th>
						  <th>创建时间</th>
						  <th>操作</th>
					  </tr>
					  </thead>
					  <tbody>
					  <tr>
						  <c:forEach items="${model.items}" var="item" varStatus="itemStatus">
					  <tr  id="row_${item.id}">
						  <td>${item.project_name}</td>
						  <td>${item.item_name}</td>
						  <td><fmt:formatNumber value="${item.suggest_price}" type="currency" pattern="0.00"/></td>
						  <c:choose>
							  <c:when test="${item.is_core == 1}">
								  <td  align="center" class="cdr fw7">是 </td>
							  </c:when>
							  <c:otherwise>
								  <td  align="center" class="cdr fw7">否</td>
							  </c:otherwise>
						  </c:choose>
						  <c:choose>
							  <c:when test="${item.is_self_channel == 1}">
								  <td  align="center" class="cdr fw7">是 </td>
							  </c:when>
							  <c:otherwise>
								  <td  align="center" class="cdr fw7">否</td>
							  </c:otherwise>
						  </c:choose>
						  <td>${item.real_name}</td>
						  <td>${item.cat1_name}-${item.cat2_name}-${item.cat3_name}</td>
						  <td><fmt:formatDate value="${item.create_time}"  type="both" pattern="yyyy-MM-dd HH:mm:ss"/></td>


						  <td align="center" align="center" >

							  <a  href="javascript:edit('${item.id}');" name="btnedit"  class="buttonrole" style="margin-left: 5px"  >编辑</a>


							  <a  href="javascript:del('${item.id}');"  name="btndel" class="buttonrole" style="margin-left: 5px"  >删除</a>




						  </td>
					  </tr>
					  </c:forEach>
					  </tr>

					  </tbody>
				  </table>

			  </div></div> <!-- /widget-body -->
             <div class="pagin" class="widget-footer">
             	<vp:pages  cpage="${model.cpage}"  totalCount="${model.totalCount}"  pageSize="${model.pageSize}"   />
   			</div>   
          </div> <!-- /widget -->
        </div> <!-- /row-fluid -->
        
      <!-- /Main window -->
      
    	</div>
    </div>
    </form>
    </div><!-- wrap ends-->
	
  	<div id="edit" style="display:none;width: 100%;height: 100%;overflow:hidden;position:absolute;left:0;top:0;right:0;bottom:0;">
        <iframe id="editFrame" width="100%" height="100%"  frameborder="0" border="0" scrolling="auto"></iframe>
    </div>
   
  </body>
  <script type="text/javascript">
	$(document).ready(function(){
		loadtree();
	});
	function loadtree(){
		postData="1=1";
		var domainUrl="${pageContext.request.contextPath}/set/category/cateview";
		 $.ajax({
	           type: "POST",
	           url: domainUrl,
	           data: postData,
	           contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	           async: true, // 同步  true 异步。默认是异步
	           error: function(resultdata) {
	           	//layer.closeAll();
	           },
	           success: function(resultdata) {
					$('#treediv').html(resultdata);
					 $("#tree").treeview({  
			        	  collapsed: true  
		    			});  
				 	 $("#treediv").hide();
	           }
	       });
	}
	
	function showCategory(){
		$("#treediv").show();
	}
	function selectcategory(cateLevel,categoryId,category3Name,category2Name,category1Name){
		$('#cateId').val(categoryId);
		$('#catLevel').val(cateLevel);
		if(cateLevel==1){
			$('#catName').val(category1Name);
		}
		if(cateLevel==2){
			$('#catName').val(category1Name + ">" + category2Name);
		}
		if(cateLevel==3){
			$('#catName').val(category1Name + ">" + category2Name + ">" + category3Name);
		}		
		$('#divCateName').html(category1Name + ">" + category2Name + ">" + category3Name);
		$("#treediv").hide();
	}
	$("#treediv1").hover(function (){  
         // $(".content").show();  
	 	},function (){  
	 	$("#treediv").hide();  
	 });  

	function seach(){
		$("#cpage").val(1);
		oksubmit();
	}
	function oksubmit() {
		var domainUrl="${pageContext.request.contextPath}/set/product/index";
		var objform = document.getElementById('seachform');
		objform.action=domainUrl;
	    objform.submit();
	}	
	function exportXls(){
		var domainUrl="${pageContext.request.contextPath}/set/product/export";
		  var objform = document.getElementById('seachform');
		  objform.action=domainUrl;
		 // alert(objform.action);
		    objform.submit();
	}
	function del(id){		
		layer.confirm('确认要删除此商品吗', {
			  btn: ['确认','取消'] //按钮
			}, function(){
				sendOpTo(id);
			}, function(){
			  
			});			
	}
	function sendOpTo(id){
		layer.load(1, {shade: [0.5,'#fff']});
		var postData="itemId=" + id;
		 $.ajax({
	            type: "POST",
	            url: "del",
	            data: postData,
	            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	            async: true, // 同步  true 异步。默认是异步
	            dataType: 'json',
	            error: function(resultdata) {
	            	layer.closeAll();
	            },
	            success: function(resultdata) {
	            	layer.closeAll();
	                if(resultdata.returnCode=="0000"){               	
	                	layer.alert('操作成功',{icon: 1}, function(){
	                		layer.closeAll();
	                	 	 oksubmit();
	                	});
	                }else{
	                	layer.alert(resultdata.returnMessage);
	                }
	            }
	        });
	}
	
    function editReturn() {
       layer.closeAll();
       oksubmit();
    }
    function closeAll() {
        layer.closeAll();
     }
    function edit(id){
		var domainUrl="edit?itemId=" + id;
		layer.open({
			  type: 2,
			  title: '产品',
			   area: ['630px', '550px'],
			   content: domainUrl //iframe的url
	      }); 
		 //$('#wrap').hide();
	    // $('#editFrame').attr("src", domainUrl);
	    // $('#edit').show(); 
	}
    function configMenu(id){
    	var domainUrl="config?roleId=" + id;
		
		 $('#wrap').hide();
	     $('#editFrame').attr("src", domainUrl);
	     $('#edit').show(); 
    }
	function reset(userId){
		var postData="userId=" + userId;
		 $.ajax({
	            type: "POST",
	            url: "resetPassword",
	            data: postData,
	            contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	            async: true, // 同步  true 异步。默认是异步
	            dataType: 'json',
	            error: function(resultdata) {
	            	layer.closeAll();
	            },
	            success: function(resultdata) {
	            	layer.closeAll();
	                if(resultdata.returnCode=="0000"){               	
	                	layer.alert('操作成功',{icon: 1}, function(){
	                		layer.closeAll();
	                	 	 oksubmit();
	                	});
	                }else{
	                	layer.alert(resultdata.returnMessage);
	                }
	            }
	        });
	}
	</script>
</html>
